package com.sky.ContactManager;

import java.util.ArrayList;

import com.sky.ContactManagerbase.Abonnee;
import com.sky.ContactManagerbase.Contact;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;



public class ContactAdapter extends BaseAdapter /*implements OnClickListener*/ {
	private LayoutInflater		mInflater;
	public ArrayList<Contact> contacts = new ArrayList<Contact>();
	public ContactAdapter(Context context, Abonnee abonnee) {
		Log.d("ProduitAdapter","25" );
		contacts = abonnee.contact;
		this.mInflater = LayoutInflater.from(context);
	}
	public static class ViewHolder {
		TextView txtText;
		Button retirer;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return contacts.size();
		
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return contacts.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Log.d("ProduitAdapter","54" );
		ViewHolder holder;
		
		if (convertView == null) {
			convertView 					= mInflater.inflate(R.layout.item_contact, null);
			holder 							= new ViewHolder();
			holder.txtText					= (TextView) convertView.findViewById(R.id.textView1);
			//holder.retirer					=(Button)convertView.findViewById(R.id.button1);
			//holder.retirer.setOnClickListener(this);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
			final Contact item 			= contacts.get(position);
			holder.txtText				 	.setText(item.lastname+"  "+item.firstname);

		return convertView;
		
	}

	/*@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Log.i("retire", "clicked");
		Log.i("id",v.toString());
		Log.i("id",Integer.toString(v.getId()));
		
		
		
	}*/

}
